﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.Web.DynamicData;
using System.Data.SqlClient;

namespace manage4systemsFornecedoresInsert
{
    public partial class Insert : System.Web.UI.Page
    {
        protected MetaTable table;

        protected void Page_Init(object sender, EventArgs e)
        {
            DynamicDataManager1.RegisterControl(DetailsView1);
            Session["jadefiniufoco"] = "Nao";   
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            table = DetailsDataSource.GetTable();
            Title = table.DisplayName;   

        }

        protected void DetailsView1_ItemCommand(object sender, DetailsViewCommandEventArgs e)
        {
            if (e.CommandName == DataControlCommands.CancelCommandName)
            {
                Response.Redirect(table.ListActionPath);
            }
        }

        protected void DetailsView1_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
        {
            string codigoEdital = "";
            if (e.Exception == null || e.ExceptionHandled)
            {
                //Aqui temos que definir o status do último edital cadastrado como S de Solicitado
                //SqlConnection sqlc = new SqlConnection(ConfigurationManager.AppSettings["baseDados"]);
                //sqlc.Open();
                ////Resgatar o maior código cadastrado
                //string q = "select max(codigoEdital) as codigoEdital from edital";
                //SqlCommand cmd = new SqlCommand(q, sqlc);
                //SqlDataReader myReader = cmd.ExecuteReader();
                //if (myReader != null)
                //{
                //    while (myReader.Read())
                //    {
                //        codigoEdital = myReader["codigoEdital"].ToString();
                //    }
                //}
                ////Alterar o registro
                //string a = "update edital set statusEdital = 'S' where codigoEdital = "+codigoEdital;
                //SqlCommand alterar = new SqlCommand(a, sqlc);
                //alterar.ExecuteNonQuery();

                Response.Redirect(table.ListActionPath);
            }
        }
    }
}
